package org.thread.test00.demo08.t03;

/**
 * 帐号
 *
 * @author ZQX
 * @date 2025-03-13
 */
public class Account {
    /**
     * 存款
     */
    private double money;

    public Account() {
    }

    public Account(double money) {
        this.money = money;
    }

    /**
     * 取钱
     *
     * @param user  取钱用户
     * @param money 取钱金额
     */
    public synchronized void getMoney(String user, double money) {
        System.out.printf("%s取了%.1f元，", user, money);


        // 余额充足
        if (this.money > money) {

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            this.money = this.money - money;
            System.out.printf("余额为：%.1f! %n", this.money);
            return;
        }

        // 余额不充足
        System.out.println("取款失败，余额不足！");
    }

    /**
     * 存钱 - 此练习不关心存钱业务（略）
     *
     * @param user  用户
     * @param money 金额
     */
    public void saveMoney(String user, double money) {

    }
}
